/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
 // 迭代
func insertIntoBST(root *TreeNode, val int) *TreeNode {
    node := root
    var pNode *TreeNode
    if root == nil {
        return &TreeNode{Val: val}
    }
    for node != nil {
        if node.Val > val {
            pNode = node 
            node = node.Left
        } else if node.Val < val {
            pNode = node 
            node = node.Right
        }
    }
    if pNode.Val < val {
        pNode.Right = &TreeNode{Val:val}
    } else {
        pNode.Left = &TreeNode{Val:val}
    }
    
    return root
}